package cn.virens.mybatis.mapper.example.util;

import java.util.Collection;
import java.util.Map;

import cn.virens.common.exception.APIException;

public class Util {

	public static String notNull(Object value) throws APIException {
		if (value == null || isEmpty(value)) {
			throw new APIException("条件空");//
		} else {
			return "";
		}
	}

	public static boolean isEmpty(Object value) throws APIException {
		if (value != null && value.getClass().isArray()) {
			return ((Object[]) value).length <= 0;
		} else if (value instanceof CharSequence) {
			return ((CharSequence) value).length() <= 0;
		} else if (value instanceof Collection) {
			return ((Collection<?>) value).isEmpty();
		} else if (value instanceof Map) {
			return ((Map<?, ?>) value).isEmpty();
		} else {
			return value == null;
		}
	}

	public static boolean isNotEmpty(Object value) throws APIException {
		return value != null && !isEmpty(value);
	}
}
